package com.fwtai.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.datasource.DaoHandle;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 商品活动促销访问数据库
 * @作者 田应平
 * @版本 v1.0
 * @创建时间 2023-05-15 12:54:16
 * @QQ号码 444141300
 * @Email service@yinlz.com
 * @官网 <url>http://www.fwtai.com</url>
*/
@Repository
public class GoodsPromotionDao{

  private final DaoHandle dao;

  public GoodsPromotionDao(final DaoHandle dao){
    this.dao = dao;
  }

  @Transactional
  public int add(final PageFormData formData,final ArrayList<HashMap<String,Object>> list){
    final int rows = dao.execute("goods_promotion.add",formData);
    dao.execute("goods_promotion.addIntegral",list);
    return rows;
  }

  public int edit(final PageFormData formData){
    return dao.execute("goods_promotion.edit",formData);
  }

  @Transactional
  public int edit(final PageFormData formData,final ArrayList<HashMap<String,Object>> list){
    final int rows = dao.execute("goods_promotion.edit",formData);
    dao.execute("goods_promotion.editIntegral",list);
    return rows;
  }

  @Transactional
  public int edit(final PageFormData formData,final ArrayList<HashMap<String,Object>> list,final HashMap<String,Object> params){
    dao.execute("goods_promotion.delPromotionIntegral",params);
    final int rows = dao.execute("goods_promotion.edit",formData);
    dao.execute("goods_promotion.editIntegral",list);
    return rows;
  }

  public Long queryExistById(final long kid){
    return dao.queryForLong("goods_promotion.queryExistById",kid);
  }

  public HashMap<String,Object> queryById(final long kid){
    return dao.queryForHashMap("goods_promotion.queryById",kid);
  }

  public List<HashMap<String,Object>> getPromotionGoodsInfo(final long kid){
    return dao.queryForListHashMap("goods_promotion.getPromotionGoodsInfo",kid);
  }

  public int delById(final long kid){
    return dao.execute("goods_promotion.delById",kid);
  }

  public int delByKeys(final long[] list){
    return dao.execute("goods_promotion.delByKeys",list);
  }

  public List<HashMap<String,Object>> getListData(final PageFormData formData){
    return dao.queryForListHashMap("goods_promotion.listData",formData);
  }

  public List<HashMap<String,Object>> queryGoods(){
    return dao.queryForListHashMap("goods_promotion.queryGoods");
  }

  public Integer getListTotal(final PageFormData formData){
    return dao.queryForInteger("goods_promotion.listTotal",formData);
  }
}